package com.itheima.config;

import com.itheima.utils.AliOSSUtils;
import com.itheima.utils.AliOssProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: 周训发
 * @CreateTime: 2025-10-23
 * @Description: AliOSS配置类
 * @Version: 1.0
 */

@Configuration
@Slf4j
public class OssConfiguration {
    @Bean  //交给spring容器管理
    @ConditionalOnMissingBean   //保证spring容器中只有一个utils对象
    public AliOSSUtils aliOSSUtils(AliOssProperties aliOssProperties){
        log.info("开始创建阿里云文件上传工具类对象：{}",aliOssProperties);
        return new AliOSSUtils(aliOssProperties.getEndpoint(),
                aliOssProperties.getAccessKeyId(),
                aliOssProperties.getAccessKeySecret(),
                aliOssProperties.getBucketName() );

    }
}
